<template>
  <div class='login'>
    <div class='myLogoa'>
      <img src="../../../static/index/logo.jpg"
           alt="">
    </div>
    <div class='info'>
      <div class='hed'>
        <span>账&nbsp;&nbsp;&nbsp;&nbsp;号</span>
        <input type="text"
               placeholder="请输入你的账号" v-model="UserName">
      </div>
      <div class='hed'>
        <span>密&nbsp;&nbsp;&nbsp;&nbsp;码</span>
        <input type="password"
               placeholder="请输入登录密码" v-model="UserPsd">
      </div>

      <div class="checked">
        <van-checkbox v-model="checked" @click="handleChecked" checked-color="#c30000"></van-checkbox>
        <p class="tcpMsg">已阅读并同意
          <router-link tag="a" to="/Agreement">服务协议</router-link>
          和
          <router-link to="/Agreement" tag="a">隐私政策</router-link>
        </p>
        <!--        serviceAgreement-->
      </div>
      <router-link to='/forgetPsd'
                   class='forget'>忘记密码?
      </router-link>
    </div>
    <button class='enter' @click="handleClickBtn">登录</button>
    <router-link class='enter enters' to="/home" tag="button">暂不登录</router-link>
    <router-link to='/register'>还没有账号?立即注册!</router-link>
  </div>
</template>
<script>
  import {getStore, setStore} from '@/config/mUtils'

  export default {
    name: 'login',
    data() {
      return {
        UserName: '',
        UserPsd: '',
        checked: true
      }
    },
    computed: {
      //判断手机号码
      // rightPhoneNumber: function () {
      //   return /^1\d{10}$/gi.test(this.Username)
      // },
    },
    methods: {
      //判断是否勾选用户协议
      handleChecked() {
        console.log(1);
      },
      GetUserName() {
        // if ( getStore("userName") || getStore("userPsd") ) {
        //   this.UserName = getStore("userName")
        //   this.UserPsd = getStore("userPsd")
        // } else {
        //   // this.UserName = ''
        //   // this.UserPsd = ''
        // }
      },
      onClickLeft() {
        this.$router.go(-1)
      },
      //18137785593   tc12345
      //qq976185225   111111
      handleClickBtn() {

        if (this.UserName.length == '' || this.UserPsd.length == '') {
          this.$toast.fail('请检查输入项是否完整!')
          return
        }

        if (this.checked === false) {
          this.$toast.fail('请查看并且勾选用户协议!')
          return
        }

        var params = this.qs.stringify({
          "name": this.UserName,
          "passwd": this.UserPsd,
          "type": "app"
        })

        this.$axios.post('user/login', params).then((res) => {
          if (res.data.status === 1) {
            this.$toast.success('登陆成功')
            setStore('token', res.data.data.token)
            setStore('userName', this.UserName)
            setStore('userPsd', this.UserPsd)
            this.$router.push({
              path: '/home'
            });
          } else {
            this.$toast.fail(res.data.message)
          }
        })
      },
    },
    created() {

    },
    mounted() {
      this.GetUserName()
    }
  }
</script>
<style lang='scss' scoped>
  @import "../../../static/css/user/login.scss";

  .checked {
    float: left;
    margin-left: 50px;
    margin-top: 10px;

    .van-checkbox {
      display: inline-block;
    }

    .tcpMsg {
      display: inline-block;
      vertical-align: super;
      font-size: 25px;

      a {
        font-size: 24px;
        /*font-weight: 100;*/
        color: blue;
      }
    }

    span {
      vertical-align: super;
      /*font-size: 25px;*/
      padding-bottom: 5px;
      color: blue;
    }
  }

  .login {
    .enters {
      margin-top: -30px;
      background: #fff;
      color: #ccc;
      border: 2px solid #ccc;
    }
  }

</style>
